//
//  ViewController.m
//  Yimei
//
//  Created by xiaowu xiaowu on 2017/10/19.
//  Copyright © 2017年 xiaowu xiaowu. All rights reserved.
//

#import "ViewController.h"
#import "HzxTabbar.h"
#import "HzxBarButton.h"
#import "TPHomeRootViewController.h"
#import "TPUserRootViewController.h"
#import "TPArticleRootViewController.h"
#import "HzxNavigationController.h"


@interface ViewController ()<HzxTabBarDelegate>{
    
}
@property (nonatomic,weak)HzxTabbar *hzxTabbar;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self addTabbar];
}

-(void)addTabbar{
    
    HzxTabbar *tabBar = [[HzxTabbar alloc]init];
    self.hzxTabbar = tabBar;
    self.hzxTabbar.frame = self.tabBar.bounds;
    
    //    [self.tabBar setShadowImage:[UIImage new]];
    [tabBar addImageView];
    self.tabBar.barTintColor = TPAllBackgroundColor;
    self.tabBar.tintColor = TPAllBackgroundColor;
    [[UITabBarItem appearance]setTitleTextAttributes:@{NSFontAttributeName:fontSystemOfSize(0),NSForegroundColorAttributeName:[UIColor clearColor]} forState:UIControlStateNormal];
    [self.tabBar addSubview:tabBar];
    [self.tabBar bringSubviewToFront:tabBar];
    //    [self.hzxTabbar mas_makeConstraints:^(MASConstraintMaker *make) {
    //        make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
    //    }];
    
    tabBar.delegate = self;
    [tabBar addBarButtonWithNorName:@"Tabbar_Home_normal" andDisName:@"Tabbar_Home_select" andTitle:@"首页"];
    [tabBar addBarButtonWithNorName:@"Tabbar_Article_normal" andDisName:@"Tabbar_Article_select" andTitle:@"内容"];
    [tabBar addBarButtonWithNorName:@"Tabbar_User_normal" andDisName:@"Tabbar_User_select" andTitle:@"我的"];
    
    
    TPHomeRootViewController *homeVC = [TPHomeRootViewController new];
    TPArticleRootViewController *articleVC = [TPArticleRootViewController new];
    TPUserRootViewController *userVC = [TPUserRootViewController new];
   
    NSArray *VCArr = @[homeVC,articleVC,userVC];
    NSMutableArray *NumArray = [[NSMutableArray alloc]initWithCapacity:0];
    for(int i=0;i<VCArr.count;i++)
    {
        HzxNavigationController *BussNav = [[HzxNavigationController alloc]initWithRootViewController:VCArr[i]];
        BussNav.tabbar = tabBar;
        [ NumArray addObject:BussNav];
    }
    
    self.viewControllers = NumArray;
    
    
    self.selectedIndex = 0;
    for(UITabBarItem *subview in self.tabBar.items){
        
        subview.enabled = NO;
        
    }
    
    
    [[UITabBar appearance] setBackgroundImage:[[UIImage alloc] init]];
    [[UITabBar appearance] setShadowImage:[UIImage imageWithColor:COLORRGBA(250, 250, 250, 0.8)]];
}
-(BOOL)willChangSelIndexForm:(NSInteger)from to:(NSInteger)to{
    
    if(to == 2 && !xw_getLogin()){
        
        return NO;
    }
    return YES;
    
}
-(void)ChangSelIndexForm:(NSInteger)from to:(NSInteger)to{
    
    
    self.selectedIndex = to;
}


@end
